/*
  * ESPRESSIF MIT License
  *
  * Copyright (c) 2017 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  *
  * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case,
  * it is free of charge, to any person obtaining a copy of this software and associated
  * documentation files (the "Software"), to deal in the Software without restriction, including
  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  * to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in all copies or
  * substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  */

#ifndef _IOT_CM1106_H_
#define _IOT_CM1106_H_

#include "usart.h"

#define FRAME_TX_HEADER     0x11        /*!< Frame header */
#define FRAME_RX_HEADER     0x16        /*!< Frame header */

/**
* @brief  Sensor control command
*/
typedef enum {
    CM1106_CMD_READ_VALUE        = (uint8_t)0x01,         /*!< Read measured value */
    CM1106_CMD_ZEROING           = (uint8_t)0x03,         /*!< CO2 concentration value zeroing */
    CM1106_CMD_READ_VERSION      = (uint8_t)0x1E,         /*!< Read software version */
    CM1106_CMD_ABC               = (uint8_t)0x10,
} CM1106_cmd_t; 

typedef int32_t esp_err_t;

/* Definitions for error constants. */
#define ESP_OK          0       /*!< esp_err_t value indicating success (no error) */
#define ESP_FAIL        -1      /*!< Generic esp_err_t code indicating failure */
/**
 * @brief Write cmd and data to CM1106
 *
 * @param uart_num uart num of used to commuicate with CM1106
 * @param cm1106_cmd control command
 * @param data_buf Pointer of data buffer
 * @param data_len data length (byte)
 *
 * @return
 *     - ESP_OK Success
 *     - Others Fail
 */
esp_err_t cm1106_write_data(CM1106_cmd_t cm1106_cmd, uint8_t *data_buf, uint8_t data_len);

/**
 * @brief Write cmd and data to CM1106
 *
 * @param uart_num uart num of used to commuicate with CM1106
 * @param cm1106_cmd Pointer of control command
 * @param data_buf Pointer of data buffer
 * @param data_len data length (byte)
 *
 * @return
 *     - ESP_OK Success
 *     - Others Fail
 */
esp_err_t cm1106_read_data(CM1106_cmd_t *cm1106_cmd, uint8_t *data_buf, uint8_t *data_len);

/**
 * @brief CM1106 test
 *
 * @param uart_num uart num of used to commuicate with CM1106
 *
 * @return
 *     - No return
 */
void cm1106_test_task(void);

#endif

